#include <bits/stdc++.h>

using namespace std;
#define int long long

void solve()
{
    int n, l, r, k;
    cin >> n >> l >> r >> k;
    if (n & 1) cout << l << '\n';
    else
    {
        unsigned long long x = bit_floor((unsigned long long)l) << 1;
        if (r >= x && n >= 4)
        {
            if (k <= n - 2) cout << l << '\n';
            else cout << x << '\n';
        }
        else cout << -1 << '\n';
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}